﻿using Tfs.OnTheRoad.Commands;
using Tfs.OnTheRoad.Model;
namespace Tfs.OnTheRoad.ViewModel
{
    /// <summary>
    /// Work Items List ViewModel
    /// </summary>
    public class WorkItemListViewModel : BaseListViewModel<WorkItem>
    {
        public NavigateToWorkItemCommand NavigateToWorkItem
        {
            get;
            private set;
        }

        private string _workItemType;

        public string WorkItemType
        {
            get { return _workItemType; }
            set
            {
                _workItemType = value;
                RaisePropertyChanged("WorkItemType");
            }
        }

        private Query _workItemQuery;
        public Query WorkItemQuery
        {
            get { return _workItemQuery; }
            set
            {
                _workItemQuery = value;
                RaisePropertyChanged("WorkItemQuery");
            }
        }
        private Build _currentBuild;
        public Build CurrentBuild
        {
            get { return _currentBuild; }
            set { _currentBuild = value; }
        }
        private Changeset _currentChangeset;
        public Changeset CurrentChangeset
        {
            get { return _currentChangeset; }
            set { _currentChangeset = value; }
        }
        public WorkItemListViewModel(Changeset changeset)
            : this()
        {
            NavigateToWorkItem = new NavigateToWorkItemCommand();
            _currentChangeset = changeset;
            _entityCollectionName = string.Format("Changesets({0})/WorkItems", _currentChangeset.Id);
        }


        public WorkItemListViewModel(Build build):this()
        {
            NavigateToWorkItem = new NavigateToWorkItemCommand();
            _currentBuild = build;
            _entityCollectionName = string.Format("Builds(Project='{0}',Definition='{1}',Number='{2}')/WorkItems", _currentBuild.Project, _currentBuild.Definition, _currentBuild.Number);
        }

        public WorkItemListViewModel()
            : base()
        {
            NavigateToWorkItem = new NavigateToWorkItemCommand();
            PageTitle = "Work Items";
            OrderBy = "CreatedDate desc";
            _entityCollectionName = "WorkItems";//Default
        }

        public WorkItemListViewModel(string path)
            : base(path)
        {
        }

        public override string GetNoResultsFoundMessage()
        {
            return "No Work Items were found.";
        }

        private string _entityCollectionName;

        internal string EntityCollectionName
        {
            get { return _entityCollectionName; }
            set { _entityCollectionName = value; }
        }
        

        public override string GetEntityCollectionName()
        {
            return _entityCollectionName;
        }


    }
}
